home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- organization: Xenix Support, FICC
- subject: v10i083: Parse ARGH: missing file from parseargs patches
- from: peter@ficc.uu.net (Peter da Silva)
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 10, Issue 83
- Submitted-by: peter@ficc.uu.net (Peter da Silva)
- Archive-name: parseargs.p2
-
- This isn't strictly speaking a patch... it's an extra file required by the
- first set of patches. I should just have posted the whole thing again...
-
- :
- #! /bin/sh
- # This is a shell archive, created at Ferranti International Controls Corp.
- # by peter (Peter da Silva +1 713 274 5180) on Fri Feb 23 05:45:53 1990
- # Remove anything before the "#! /bin/sh" line, then unpack it by saving
- # it into a file and typing "sh file". If you do not have sh, you need
- # unshar, a dearchiving program which is widely available. In the absolute
- # wost case, you can crack the files out by hand.
- # If the archive is complete, you will see the message "End of archive."
- # at the end.
- # This archive contains the following files...
- # 'arglist.c'
- # To extract them, run the following through /bin/sh
- echo x - arglist.c
- sed 's/^X//' > arglist.c << '//END_OF_FILE'
- X#include <parseargs.h>
- X#include <ctype.h>
- X
- X#ifdef __STDC__
- Xtypedef void *pointer;
- X#else
- Xtypedef char *pointer;
- X#endif
- X
- Xextern pointer malloc();
- X
- X#define ALL_AD ad = argd; ad->ad_name != '\0'; ad++
- X#define ALL_DEFS ad = _DefaultArgs; ad->ad_name != '\0'; ad++
- X
- Xextern char *ProgName;
- X
- X/* Argument list utility routines. After processing, parseargs calls
- X * cleanup_lists to reverse all argument lists so they stay in order.
- X */
- X
- X/* Reverse a list */
- Xstruct arglist *reverselist(from)
- Xstruct arglist *from;
- X{
- X struct arglist *to, *tmp;
- X
- X to = NULL;
- X while(from) {
- X tmp = from; /* remove top from old list */
- X from = from->nl_next;
- X tmp->nl_next = to; /* insert top in new list */
- X to = tmp;
- X }
- X return to;
- X}
- X
- X/* Reverse all arglists in argd */
- Xcleanup_lists(argd)
- XARGDESC *argd;
- X{
- X ARGDESC *ad;
- X
- X for(ALL_AD) {
- X if( (ad->ad_flags & ARGLIST) &&
- X *(struct arglist **)ad->ad_valp) {
- X *(struct arglist **)ad->ad_valp =
- X reverselist( *(struct arglist **)ad->ad_valp );
- X }
- X }
- X}
- X
- X/*
- X** ARGlist -- list argument translation routines.
- X**
- X** Each of these converts a parameter value to the internal form,
- X** including validity checking. Their parameters and return values
- X** all behave identically. These are the routines for dealing with
- X** lists...
- X**
- X** Parameters:
- X** ad -- the argument descriptor for this parameter.
- X** vp -- a pointer to the string input value.
- X** copyf -- if TRUE, the value will be destroyed later,
- X** and so should be copied if it will be retained
- X** (as for a string).
- X**
- X** Returns:
- X** TRUE -- if the conversion was successful. The actual
- X** value should be added to the list stored in the
- X** location indicated by ad->ad_valp.
- X** FALSE -- if the conversion failed. The reason for failure
- X** should be diagnosed using usrerr().
- X**
- X** Side Effects:
- X** The value should be stored through ad->ad_valp.
- X*/
- X
- XBOOL
- XlistStr(ad, vp, copyf)
- X register ARGDESC *ad;
- X register char *vp;
- X BOOL copyf;
- X{
- X char *cp;
- X struct arglist *nl;
- X
- X if (copyf)
- X {
- X register int i;
- X
- X i = strlen(vp) + 1;
- X cp = (char *) malloc(i);
- X if(!cp) {
- X usrerr("out of memory saving string %s", ad->ad_prompt);
- X return FALSE;
- X }
- X bcopy(vp, cp, i);
- X }
- X else
- X {
- X cp = vp;
- X }
- X
- X nl = (struct arglist *) malloc(sizeof *nl);
- X if(!nl) {
- X usrerr("out of memory saving arg %s", ad->ad_prompt);
- X if(copyf) free(cp);
- X return FALSE;
- X }
- X
- X nl->nl_next = *(struct arglist **) ad->ad_valp;
- X nl->nl_val = (ARBPTR)cp;
- X *(struct arglist **) ad->ad_valp = nl;
- X return (TRUE);
- X}
- X
- //END_OF_FILE
- echo "End of archive."
- # end of archive.
- exit 0
- --
- _--_|\ Peter da Silva. +1 713 274 5180. <peter@ficc.uu.net>.
- / \
- \_.--._/ Xenix Support -- it's not just a job, it's an adventure!
- v "Have you hugged your wolf today?" `-_-'
-
-
-